﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include file="/WEB-INF/include/header.jsp"%>

  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">

    <div class="panel panel-default x-panel x-panel-layout">

      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/ecommerce">电商管理</a></li>
          <li class="active">订单管理</li>
        </ol>
      </div>

      <div class="panel-body">

        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">

          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>订单管理&nbsp;-&nbsp;会籍卡订单</span></h2>
              <div class="pull-right">
                <c:choose>
                  <c:when test="${not empty currentPrincipal.site}">
                    <span class="current-branchCode">${currentPrincipal.site.name}</span>
                  </c:when>
                  <c:otherwise>
                    <select name="siteId">
                      <option value="">所有门店</option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${site.id == param.siteId ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
          </div>
          
          
          <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;">
            <ul class="nav nav-pills x-breadcrumb-nav">
              <li class="pull-left ${status == 'created' ? 'active' : ''}"><a href="${ctx.host}/card-orders?status=created">待付款</a></li>
              <li class="pull-left ${status == 'pending' ? 'active' : ''}"><a href="${ctx.host}/card-orders?status=pending">待激活</a></li>
              <li class="pull-left ${status == 'processing' ? 'active' : ''}"><a href="${ctx.host}/card-orders?status=processing">已激活</a></li>
              <li class="pull-left ${status == 'compelte' ? 'active' : ''}"><a href="${ctx.host}/card-orders?status=compelte">已完成</a></li>
              <li class="pull-left ${status == 'canceled' ? 'active' : ''}"><a href="${ctx.host}/card-orders?status=canceled">已取消</a></li>
              <li class="pull-left ${status == 'refunded' ? 'active' : ''}"><a href="${ctx.host}/card-orders?status=refunded">已退款</a></li>
            </ul>
          </div>
          
          
          <div class="form-horizontal clearfix" style="margin-bottom: ${refer == 'search' ? '0' : '20'}px">
          <c:if test="${refer == 'search'}">
              <div class="form-group pull-left" style="width: 40%; margin-bottom: 0px;">
                <label class="control-label col-xs-4">订单总数：</label>
                <div class="col-xs-3">
                  <p class="form-control-static">${total}</p>
                </div>
              </div>
            </c:if>
            <div class="btn-group pull-right">
                <a href="${ctx.host}/card-orders/create-card" data-target="#create-card" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;手动添加
                </a>
              <a href="${ctx.host}/card-orders/search${not empty queryString ? '?' : ''}${queryString}" data-target="#" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                <i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;过滤查询
              </a>
            </div>
          </div>

          <table class="table table-striped table-hover x-table" style="margin-bottom:20px;">
            <thead>
              <tr>
                <th>订单号</th>
                <th>下单用户</th>
                <th>产品</th>
                <th>金额</th>
                <th>门店</th>
                <th>创建时间</th>
                <th>订单状态</th>
                <th>销售人员</th>
                <th class="text-center">操作</th>
              </tr>
            </thead>
            <tbody>
              <c:forEach var="order" items="${orders}">
                <tr>
                  <td>
                    <a href="${ctx.host}/card-orders/${order.id}">${order.code}</a><br>
                    <fmt:formatDate value="${order.payTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                  </td>
                  <td style="max-width: 150px;" class="ellipsis">
                    ${order.user.name}（${order.user.wechat.code}）<br>
                    ${order.user.mobile}
                  </td>
                  <td style="max-width: 150px;" class="ellipsis">
                    ${order.course.name}
                  </td>
                  <td style="max-width: 150px;" class="ellipsis">
                    <fmt:formatNumber value="${order.price / 100}" pattern="0.00" maxFractionDigits="2" />
                  </td>
                  <td style="max-width: 150px;" class="ellipsis">${order.site.name}</td>
                  <td style="max-width: 150px;" class="ellipsis">
                    <fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm"/>
                  </td>
                  <td style="max-width: 150px;" class="ellipsis">
                    ${order.orderStatus.description} <br />
                    ${order.paymentStatus.description}
                  </td>
                  <td>${empty order.salesman ? '-' : order.salesman.name}</td>
                  <td class="text-center">
                    <a href="${ctx.host}/card-orders/${order.id}">详情</a>&nbsp;&nbsp;
                    <c:if test="${currentPrincipal.root || currentPrincipal.admin || currentPrincipal.areaServer}">
                      <c:if test="${order.orderStatus == 'PENDING' || order.orderStatus == 'PROCESSING'}">
                        <a href="${ctx.host}/${type}-orders/${order.id}/price?priceType=sale" data-target="#deposit" data-toggle="modal">修改价格</a>&nbsp;&nbsp;
                      </c:if>
                    </c:if>
                    <c:if test="${order.unpaid}">
                      <c:if test="${order.deposit == 0}">
                        <a href="${ctx.host}/card-orders/${order.id}/deposit" data-target="#deposit" data-toggle="modal">定金</a>&nbsp;&nbsp;
                      </c:if>
                      <a href="${ctx.host}/card-orders/${order.id}/offer" data-target="#offer" data-toggle="modal">部分金额</a>&nbsp;&nbsp;
                      <a href="${ctx.host}/card-orders/${order.id}/pay" data-target="#pay" data-toggle="modal">手动支付</a>&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${order.availableCancel()}">
                      <a href="${ctx.host}/individual-orders/${order.id}/close" data-target="#refund" data-toggle="modal">关闭</a>&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${order.availableRefund() and !currentPrincipal.siteServer and !currentPrincipal.areaServer}">
                      <a href="${ctx.host}/individual-orders/${order.id}/refund" data-target="#refund" data-toggle="modal">退款</a>&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${order.availableChangeSalesman()}">
                      <a href="${ctx.host}/card-orders/${order.id}/change-salesman" data-target="#change-salesman" data-toggle="modal">销售人员</a>
                    </c:if>
                    <c:if test="${order.paymentStatus.paid and empty persist.orderInvoiceRecord(order.id)}">
                      <a href="${ctx.host}/card-orders/${order.id}/invoice" data-target="#invoice" data-toggle="modal">开具发票</a>&nbsp;&nbsp;
                    </c:if>
                    <c:if test="${order.paymentStatus.paid}">
                      <a href="${ctx.host}/card-orders/${order.id}/distribution-channel" data-target="#distribution-channel" data-toggle="modal">销售渠道</a>&nbsp;&nbsp;
                    </c:if>
                    <%-- <c:if test="${order.paymentStatus.paid and order.payingPrice > 0}">
                      <a href="${ctx.host}/card-orders/${order.id}/balance-payment" data-target="#balance-payment" data-toggle="modal">尾款</a>&nbsp;&nbsp;
                    </c:if> --%>
                  </td>
                </tr>
              </c:forEach>
            </tbody>
          </table>
          
          <div class="form-horizontal clearfix">
            
            <c:if test="${refer == 'search'}">
                <div class="form-group pull-left" style="width: 60%">
                  <label class="control-label col-xs-3">查询总计：</label>
                  <div class="col-xs-4" style="padding-left: 0px;">
                    <p class="form-control-static">${total}条记录<c:if test="${total > 0 and total < 5000}">&nbsp;&nbsp;&nbsp;&nbsp;<a href="${ctx.host}/card-orders/export?export=true&${queryString}">导出报表</a></c:if></p>
                  </div>
                </div>
            </c:if>
            
            <jsp:include page="/WEB-INF/include/page.jsp">
              <jsp:param name="url" value="card-orders" />
              <jsp:param name="queryString" value="${queryString}" />
            </jsp:include>
            
          </div>

        </div>

      </div>

    </div>

  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/ecommerce/order/card-order-list.js">
    <script type="text/javascript">
      require(['page/ecommerce/order/card-order-list'],function(page){
          page.init({status:'${status}'});
      })
    </script>
  </d:resource>
  
</body>
</html>